// Log.hpp
#pragma once
#include <iostream>
#include <cstdio>
#include <ctime>

#define INFO 1
#define WARNING 2
#define ERROR 3
#define FATAL 4

// 宏直接传INFO，会被替换成数字1，在宏参数前边带一个#，可以把宏参转化成字符串
#define LOG(level, message) Log(#level, message, __FILE__, __LINE__)

void Log(std::string level, std::string message, std::string file_name, int line)
{
    time_t t = time(nullptr);
    struct tm *ctime = localtime(&t);
    std::cout << "[" << level << "]["
              << ctime->tm_year + 1900 << "-" << ctime->tm_mon + 1 << "-" << ctime->tm_mday << " "
              << ctime->tm_hour << ":" << ctime->tm_min << ":" << ctime->tm_sec
              << "][" << message << "][" << file_name << "][" << line << "]" << std::endl;
}

// 用的时候，可以拼接字符串：
// LOG(INFO, "abc"+"def");
// char *p = "def";
// LOG(INFO, "abc"+p);